package com.yao.seckill.web.controller;


import com.yao.seckill.core.SeckillResponse;
import com.yao.seckill.web.service.ISeckillOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yaobing
 * @since 2022-08-31
 */
@RestController
@RequestMapping("/seckill-order")
public class SeckillOrderController {

    @Autowired
    private ISeckillOrderService seckillOrderService;
    @PostMapping("seckill")
    public SeckillResponse seckill(Integer goodsId){
       return seckillOrderService.doSeckill(goodsId);
    }


    @GetMapping("reset")
    public SeckillResponse resetStock(){

        seckillOrderService.doClearCache();
        return SeckillResponse.success();
    }

    @GetMapping("result")
    public SeckillResponse getResult(){
        return SeckillResponse.success(seckillOrderService.getResult());
    }
}
